import weatherService from '@/services/weather.service'
//天气模块
const weather={
    namespaced: true,
    state: {
        weatherInfo: {}
    },
    mutations: {
        set_weather: (state, dailyWeather) => {
            state.weatherInfo = dailyWeather;
        }
    },
    actions: {
        loadWeather: async ({ commit }, payload) => {
            weatherService.getWeatherInfo(payload).then((result)=>{
                if(result && result.code ==='200' && result.daily){
                    let dailyWeather=result.daily[0];
                    commit("set_weather", dailyWeather);
                }
            }); 
            
        },
    },
    getters: {
        temp: state => state.weatherInfo.tempMin? state.weatherInfo.tempMin+"~" + state.weatherInfo.tempMax +"℃": 'N/A ℃',
        textDay: state => state.weatherInfo.textDay ? state.weatherInfo.textDay: '未知',
        iconDay: state => state.weatherInfo.iconDay ? 'qi-'+state.weatherInfo.iconDay : 'qi-999'
    }
}
export default weather
